package com.example.gesture.PointerInput

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.dp


//onDoubleTap (可选)：双击时回调
//onLongPress (可选)：长按时回调
//onPress (可选)：按下时回调
//onTap (可选)：轻触时回调
@Composable
fun TapGestureDemo() {
    val boxSize = 100.dp
    var amount by remember {
        mutableStateOf(0)
    }

    Box(
        modifier = Modifier
            .size(boxSize)
            .background(Color.LightGray)
            .pointerInput(Unit) {
                detectTapGestures(
                    onDoubleTap = {
                        Log.d("xu", "双击操作")
                        amount -= 1
                    },
                    onTap = {
                        Log.d("xu", "轻触操作")
                        amount += 1
                    },
                    onLongPress = {
                        Log.d("xu", "长按操作")
                    },
                    onPress = {
                        Log.d("xu", "按下操作")
                    }
                )
            },
        contentAlignment = Alignment.Center
    ) {
        Text(text = "$amount")
    }
}